#!/usr/bin/perl

$IMG_URL = "http://particle.phys.uvic.ca/~web-atlas/atlas/feedthroughs/status/image/BrushedMetal.gif";

$query_string = $ENV{'QUERY_STRING'};
($TTYP, $ITYP, $FT, $FTYP) = split /:/, $query_string;

if ( $FTYP eq "std" ) {
  $NAME = Standard;
  $MX = 15;
} elsif ( $FTYP eq "spc" ) {
  $NAME = Special;
  $MX = 15;
} elsif ( $FTYP eq "hec" ) {
  $NAME = HEC;
  if ( $TTYP eq "WeldTests" ) {
    $MX = 12;
  } else {
    $MX = 13;
  }
} elsif ( $FTYP eq "fcl" ) {
  $NAME = FCAL;
  $MX = 15;
}

$PAGE='<html>
<body style="background-image: url(' . $IMG_URL . ')" text=navy>
<center>
<br>';
if ( $ITYP eq "CrossTalk" ) {
  $ITIT = "CrossTalk";
  $PAGE = $PAGE . '<h1>View Pulses from ' . $NAME . ' FeedThrough ' 
  . $FT . ' ' . $ITIT . ' ' . $TTYP . '</h1>';
} elsif ( $ITYP eq "Phred" ) {
  $ITIT = "Resistance";
  $PAGE = $PAGE . '<h1>View data from ' . $NAME . ' FeedThrough ' 
  . $FT . ' ' . $ITIT . ' ' . $TTYP . '</h1>';
}
$PAGE = $PAGE . '</center>
<hr>
<form action="AtlFtGetPls.pl" method="GET">
<input type="hidden" name="ttyp" value="' . $TTYP . '">
<input type="hidden" name="ityp" value="' . $ITYP . '">
<input type="hidden" name="ft"   value="' . $FT . '">
<input type="hidden" name="ftyp" value="' . $FTYP . '">
<table cellspacing=0 cellpadding=5 align=center>
<tr align=center>
<th> Select the Slot Number';

if ( $ITYP eq "CrossTalk" ) {
  $PAGE = $PAGE . '<th> Select the Pulsed Channel
  <th> Select the Scanned Channel';
}

$PAGE = $PAGE . '</tr>
<tr align=center>
<td> <select name="slt" size=1>';
if ( $TTYP eq FinalTests || $TTYP eq ReceptionTests || $TTYP eq WeldTests ) {
  $PAGE = $PAGE . '<option slected> slot01a';
} elsif ( $TTYP eq ColdTests ) {
  $PAGE = $PAGE . '<option slected> slot01';
}
for ($i=2; $i<=$MX; $i++) {
  if ( $i < 10 ) {
    if ( $TTYP eq FinalTests || $TTYP eq ReceptionTests || $TTYP eq WeldTests ) {
      if ( ! ( $FTYP eq "fcl" & $i == 8 & $TTYP eq WeldTests )) {
        $PAGE = $PAGE . "<option> slot0" . "$i" . "a\n";
      }
    } elsif ( $TTYP eq ColdTests ) {
      $PAGE = $PAGE . "<option> slot0" . "$i" . "\n";
    }
  } else { 
    if ( $TTYP eq FinalTests || $TTYP eq ReceptionTests || $TTYP eq WeldTests ) {
      $PAGE = $PAGE . "<option> slot" . "$i" . "a\n";
    } elsif ( $TTYP eq ColdTests ) {
      $PAGE = $PAGE . "<option> slot" . "$i" . "\n";
    }
  }
}

if ( $TTYP eq FinalTests || $TTYP eq ReceptionTests || $TTYP eq WeldTests ) {
  for ($i=1; $i<=$MX; $i++) {
    if ( $i < 10 ) {
      if ( ! ( $FTYP eq "fcl" & $i == 8 & $TTYP eq WeldTests )) {
        $PAGE = $PAGE . "<option> slot0" . "$i" . "b\n";
      }
    } else { 
      $PAGE = $PAGE . "<option> slot" . "$i" . "b\n";
    }
  }
}

$PAGE = $PAGE . '</select>';
if ( $ITYP eq "CrossTalk" ) {
  $PAGE = $PAGE . '<td> <select name="pls" size=1>
  <option selected> 01';
  for ($i=2; $i<=64; $i++) {
    if ( $i < 10 ) {
      $PAGE = $PAGE . "<option> 0" . "$i\n";
    } else { 
      $PAGE = $PAGE . "<option> $i\n";
    }
  }
  $PAGE = $PAGE . '</select>
  <td> <select name="scn" size=1>
  <option selected> pulsed
  <option>          minus 2
  <option>          plus 2
  <option>          opposite
  </select>';
} else {
  $PAGE = $PAGE . '<input type="hidden" name="pls" value=0>
  <input type="hidden" name="scn" value=0>';
}
$PAGE = $PAGE . '</tr>
</table>
<br> <br>
<center>
<input type="submit" value="submit">
</form>
</center>
<br> <br>
<hr>
</body>
</html>';

print "Content-type: text/html\n\n";
print $PAGE;

exit(0);
